import Vue from 'vue'
import VueRouter from 'vue-router'
import Index from '../views/index.vue'
import Login from '../views/Login.vue'
import Notice from '../views/notice.vue'
import PersonalCenter from '../views/personalCenter.vue'
import Myrepair from '../views/myrepair.vue'
import AccountManage from '../components/AccountManage.vue'
import AreaManage from '../back/AreaManage.vue'
import MaterialTotalManage from '../back/MaterialTotalManage.vue'
import MaterialUseManage from '../back/MaterialUseManage.vue'
import ProjectManage from '../back/ProjectManage.vue'
import RepairManage from '../back/RepairManage.vue'
import PublicManage from '../back/PublicManage.vue'
import RoleManage from '../back/RoleManage.vue'
import ServiceManage from '../back/ServiceManage.vue'


Vue.use(VueRouter)
//获取原型对象上的push函数
const originalPush = VueRouter.prototype.$push
//修改原型对象中的push方法
VueRouter.prototype.$push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

const routes = [
  {
    path: '/',
    name: 'Index',
    component: Index
  },
  {
    path: '/login',
    name: 'Login',
    component: Login
  },
  {
    path: '/notice',
    name: 'Notice',
    component: Notice
  },
  {
    path: '/personalCenter',
    name: 'PersonalCenter',
    component: PersonalCenter,
	children:[
			  {
			  	path:"/personalCenter/AccountManage",
			  	component:AccountManage,
			  	name:"AccountManage"
			  },
			  {
			  	path:"/personalCenter/AreaManage",
			  	component:AreaManage,
			  	name:"AreaManage"
			  },
			  {
			  	path:"/personalCenter/MaterialTotalManage",
			  	component:MaterialTotalManage,
			  	name:"MaterialTotalManage"
			  },
			  {
			  	path:"/personalCenter/MaterialUseManage",
			  	component:MaterialUseManage,
			  	name:"MaterialUseManage"
			  },
			  {
			  	path:"/personalCenter/ProjectManage",
			  	component:ProjectManage,
			  	name:"ProjectManage"
			  },
			  {
			  	path:"/personalCenter/RepairManage",
			  	component:RepairManage,
			  	name:"RepairManage"
			  },
			  {
			  	path:"/personalCenter/PublicManage",
			  	component:PublicManage,
			  	name:"PublicManage"
			  },
			  {
			  	path:"/personalCenter/RoleManage",
			  	component:RoleManage,
			  	name:"RoleManage"
			  },
			  {
			  	path:"/personalCenter/ServiceManage",
			  	component:ServiceManage,
			  	name:"ServiceManage"
			  }
		]
  },
  {
    path: '/myrepair',
    name: 'Myrepair',
    component: Myrepair
  }
]
const router = new VueRouter({
  routes
})

// 后置守卫,前端权限控制
// router.beforeEach((to,from,next)=>{
// 	if(to.path=="/"||to.path=="/shop"){
// 		next();
// 	}
// 	else{
// 		let json = localStorage.getItem("adminRoot");
// 		console.log(json);
// 		if(json == null || json == undefined || json == ""){
// 			router.push("/");
// 		}else{
// 			next();
// 		}
// 	}
// })
export default router
